<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>代理账单统计管理</title>
    <jsp:include page="/resources/inc/head.jsp" flush="true"/>
</head>
<body>
<div id="main">
    <div id="toolbar">
        <shiro:hasPermission name="business:bill:apply"><a class="waves-effect waves-button" href="javascript:;" onclick="applyAction()"><i class="	glyphicon glyphicon-euro"></i> 申请提现</a></shiro:hasPermission>
        <shiro:hasPermission name="business:bill:log"><a class="waves-effect waves-button" href="javascript:;" onclick="logAction()"><i class="glyphicon glyphicon-th-list"></i> 账单详情</a></shiro:hasPermission>
    </div>
    <table id="table"></table>
</div>
<jsp:include page="/resources/inc/footer.jsp" flush="true"/>
<script>
    var $table = $('#table');
    $(function() {
        // bootstrap table初始化
        $table.bootstrapTable({
            url: '${basePath}/manage/bill/list',
            height: getHeight(),
            dataField:"rows",
            search: false,
            showRefresh: true,
            showColumns: true,
            clickToSelect: true,
            pagination: false,
            treeView: true,
            treeId: "id",
            treeField: "name",
            treeCollapseAll:"false",
            pagination: false,
            paginationLoop: false,
            sidePagination: 'server',
            silentSort: false,
            smartDisplay: false,
            escape: true,
            searchOnEnterKey: true,
            idField: 'id',
            maintainSelected: true,
            toolbar: '#toolbar',
            columns: [
                {field: 'ck', checkbox: true},
                {field: 'name', title: '名称'},
                {field: 'rate', title: '营业额扣除百分比(%)'},
                {field: 'amount_total', title: '总营业额'},
                {field: 'amount_rate_total', title: '可提现总额'},
                {field: 'amount_remainder', title: '剩余提现额'},
                {field: 'update_time', title: '更新时间',formatter:'detailLongDateTimeFormatter'},
                {field: 'action', title: '操作', align: 'center', formatter: 'actionFormatter', events: 'actionEvents', clickToSelect: true}
            ]
        });
    });
    window.actionEvents = {
        <shiro:hasPermission name="business:bill:apply">
        'click .apply': function(e, value, row, index) {
            applyAction([row]);
        },
        </shiro:hasPermission>
        <shiro:hasPermission name="business:bill:apply">
        'click .log': function(e, value, row, index) {
            logAction([row]);
        },
        </shiro:hasPermission>
    };

    // 格式化操作按钮
    function actionFormatter(value, row, index) {
        if(row.id == ${currentUserAgentId})
            return [
                <shiro:hasPermission name="business:bill:apply">
                '<a class="apply" href="javascript:;" data-toggle="tooltip" title="申请提现"><i class="	glyphicon glyphicon-euro"></i></a>　',
                </shiro:hasPermission>
                <shiro:hasPermission name="business:bill:log">
                '<a class="log" href="javascript:;" data-toggle="tooltip" title="账单详情"><i class="glyphicon glyphicon-th-list"></i></a>　'
                </shiro:hasPermission>
            ].join('');
    }
    // 新增
    var applyDialog;
    function applyAction(rows) {
        if(!rows){
            rows = $table.bootstrapTable('getSelections');
        }
        if(rows.length==0){
            infoDialog("请选择一条账单记录。");
            return;
        }
        applyDialog = openDialog('url:${basePath}/manage/bill/apply/'+rows[0].id,'提现申请')
    }
    // 新增
    var logDialog;
    function logAction(rows) {
        if(!rows){
            rows = $table.bootstrapTable('getSelections');
        }
        if(rows.length==0){
            infoDialog("请选择一条账单记录。");
            return;
        }
        logDialog = openDialog('url:${basePath}/manage/bill/log/'+rows[0].id,'账单详情')
    }
</script>
</body>
</html>